/**
 * Title: WADS
 * Description: Web-based Auto flow Documents System
 * Copyright: 2007
 * Company: CoE
 * @author: Old developer team
 * @version 1.1
 */

package wads.servlet;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import wads.com.WADTools;

public class GetDocumentTemplateServlet extends HttpServlet {
  private static final long serialVersionUID = -1885354527458853435L;
  
  private static final String CONTENT_TYPE = WADTools.SERVLET_CONTENT_TYPE;
  /**Initialize global variables*/
  private String app_Path;

  public void init(ServletConfig config) throws ServletException {
    super.init(config);
  }
  /**Process the HTTP Get request*/
  public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.setContentType(CONTENT_TYPE);
    //app_Path = this.getInitParameter("app_Path");
    app_Path = WADTools.APP_PATH;
    String dt_ID = request.getParameter("dt_ID");
    ServletOutputStream sos = response.getOutputStream();

    try{
      //String adtPath = this.getInitParameter("pathName") + "activeDocTemplate/";
      File htmlFile = new File(app_Path+"res/docs/activeDocTemplate/" + dt_ID + "/" + dt_ID + ".html");
      FileInputStream fis = new FileInputStream(htmlFile);
      byte[] buf = new byte[1024];
      int len = 0;
      while((len = fis.read(buf)) >= 0){
        sos.write(buf, 0, len);
      }
    //maybe you can add others information
    }
    catch(Exception e) {
      System.out.println("Exception thrown from GetDocumentTemplateServlet.doGet() while try to read html file.");
      sos.println(e.toString());
    }
  }
  /**Clean up resources*/
  public void destroy() {
  }
}
